﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace MazeWars
{
    class GameOverWindow : Window
    {
        SpriteFont font;
        Vector2 textPos, textOrig;
        Viewport vp;
        string text;
        float elapsedTime;
        const float TIME_TO_END = 3.0f;

        public GameOverWindow()
        {
            elapsedTime = 0;
            text = "Game Over";
        }

        public override void setupWindow(ContentManager cm, Viewport vp) 
        {
            font = cm.Load<SpriteFont>("Times new Roman");
            textPos = new Vector2(vp.Width / 2, vp.Height / 2);
            textOrig = font.MeasureString(text) / 2;
            this.vp = vp;
        }
        
        public override void draw(SpriteBatch sb, GraphicsDevice gd) 
        {
            gd.Viewport = vp;
            gd.Clear(Color.White);
            sb.Begin();

            sb.DrawString(font, text, textPos, Color.Black, 0, textOrig, 1.0f, SpriteEffects.None, 0);

            sb.End();
        }
        
        public override void update(KeyboardState ks, GameTime gameTime) 
        {
            elapsedTime += gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
            if (elapsedTime >= TIME_TO_END)
            {
                WindowManager.instance().changeWindow(Window.TITLE_WINDOW);
            }
        }
        
        public override void loadWindow() 
        {
            elapsedTime = 0;
        }
    }//End of class GameOverWindow
}
